package com.zzyl.common.utils.pdf;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

import java.io.IOException;
import java.io.InputStream;

/**
 * TODO
 *
 * @Author mr.wu
 * @Data #{DATE} #{TIME}
 */

public class PdfUtils {
        public static String  pdfToString(InputStream inputStream){
            PDDocument pdDocument = null;

            try {
                pdDocument = pdDocument.load(inputStream);
                PDFTextStripper pdfTextStripper = new PDFTextStripper();
                String text = pdfTextStripper.getText(pdDocument);
                return text;
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if(null!=pdDocument){
                    try {
                        pdDocument.close();
                        inputStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return null;
        }
}
